{% extends "skia_telemetry_base.html" %}

{% block content %}

<center>
{% if info_msg %}<font color="red"><b>{{ info_msg }}</b></font><br/><br/>{% endif %}
<h2>Run Admin Tasks</h2>
<br/>

{% if not admin %}<br/>Must be admin to trigger below admin tasks (contact rmistry@)<br/><br/>{% endif %}

<form action="/skia-telemetry/admin_tasks" name="all_admin_tasks" method="post">
  <table cellpadding="5" border="1">
    <tr>
      <td>
        <select name="pagesets_type">
          {% for pageset_type in pageset_types %}
            <option value="{{ pageset_type }}" {% ifequal pageset_type "Deeplinks" %}disabled{% endifequal %}>{{ pageset_type }}</option>
          {% endfor %}
        </select>
      </td>
      <td align="center">
        <input type="submit" value="Recreate Pagesets" name="admin_task" {% if not admin %}disabled{% endif %}>
      </td>
      <td align="center">
        <select name="chromium_build">
          {% for chromium_build in chromium_builds %}
            <option value="{{ chromium_build.chromium_rev }}-{{ chromium_build.skia_rev }}">{{ chromium_build.chromium_rev|slice:":7" }}-{{ chromium_build.skia_rev|slice:":7" }} (Chromium rev created on {{ chromium_build.chromium_rev_date}})</option>
          {% endfor %}
        </select>
        <br/>
        <input type="submit" value="Recreate Webpage Archives" name="admin_task" {% if not admin %}disabled{% endif %}>
      </td>
      <td align="center">
        <input type="submit" value="PDFViewer Diff" name="admin_task" {% if not pdf_admin %}disabled{% endif %}>
      </td>
    </tr>
  </table>
</form>
<br/>
<br/>

  <h2>Your previous Admin task runs</h2>
  <br/>
  <br/>
  {% if admin_tasks %}
  <table border="1" cellpadding="5">
    <tr bgcolor="#CCCCFF">
      <td><b>Task</b></td>
      <td><b>Pagesets Type</b></td>
      <td><b>Chromium Build</b></td>
      <td><b>Requested Time</b></td>
      <td><b>Completed Time</b></td>
      <td><b>Delete</b></td>
    </tr>
    {% for task in admin_tasks %}
    <tr {% if not task.completed_time %}bgcolor="#8FDF5F"{% endif %} >
      <td>{{ task.task_name }}</td>
      <td>{{ task.pagesets_type }}</td>
      <td>
        {% if task.chromium_rev and task.skia_rev %}
          <a href='https://chromium.googlesource.com/chromium/src/+/{{ task.chromium_rev }}'>{{ task.chromium_rev|slice:":7" }}</a>-<a href='https://skia.googlesource.com/skia/+/{{ task.skia_rev }}'>{{ task.skia_rev|slice:":7" }}</a>
        {% else %}
          N/A
        {% endif %}
      </td>
      <td>{{ task.requested_time }}</td>
      <td>
        {% if task.completed_time %}
          {{ task.completed_time }}
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        <form action="/skia-telemetry/admin_tasks" name="delete_admin_task" method="post">
          <input type='hidden' name='delete' value='{{ task.key.id_or_name }}'>
          <input type='submit' value='Delete' {% ifequal task.key.id_or_name oldest_pending_task_key %}disabled{% endifequal %}>
        </form>
      </td>

    </tr>
    {% endfor %}
  </table>
  {% else %}
    No Previous runs yet.
  {% endif %}

  <br/>
  <a href='all_tasks#admin'>View runs of all users</a>
</center>

{% endblock %}
